/**
 *比较两次输入密码是否一致
 */
function compare(){
    var a=document.getElementById('pwd1').value;
    var b=document.getElementById('pwd2').value;
    if(a!=b){
        alert("两次密码不一致");
        return false;
    }

}
/**
 * 判断账号是否存在
 */
function isexist(){

    var no=document.getElementById("custno").value;
    //console.log(no);
    var data = "custNo=" + no;
    var url ="customer!isExistRe";
    sendRequest("post", url, data, isExistResult);
    // return false;

}
/**
 * 判断手机号填写是否正确
 */
function isError(){

    var custphone=document.getElementById("custphone").value;

    if(!(/^1[34578]\d{9}$/.test(custphone))){
        alert("手机号码有误，请重填");
        return false;
    }
}
/**
 * 点击注册按钮是提交
 */
function register(){
    var custno = document.getElementById("custno").value;
    var custname = document.getElementById("custname").value;
    if((custname == null)||(custname=="")){
        alert("姓名不能为空！");
        return ;
    }
    var custphone= document.getElementById("custphone").value;
     if((custphone == null)||(custphone=="")){
         alert("手机号不能为空！");
         return ;
     }
    if(!(/^1[34578]\d{9}$/.test(custphone))){
        alert("手机号码有误，请重填");
        return false;
    }
    var genderSelect=document.getElementById("gender");
    var gender=genderSelect.options[genderSelect.selectedIndex].value;
    var custaddr= document.getElementById("custaddr").value;
    var custage= document.getElementById("custage").value;
    if(custaddr==""||custaddr==null){ custaddr=null;}
    if(custage==""||custage==null){ custage="0";}
    var connectSelect=document.getElementById("connect");
    var connect=connectSelect.options[connectSelect.selectedIndex].value;

    var pwd1= document.getElementById("pwd1").value;
    var pwd2= document.getElementById("pwd2").value;
    if((pwd1 == "")||(pwd1 == null)){
        alert("请输入密码！");
        return ;
    }else{
        if((pwd2 == "")||(pwd2 == null)){
        alert("请输入确认密码！");
        return ;
       }

    }

    var date="custName="+custname+"&custPhone="+custphone+"&gender="+gender+"&custAddr="+custaddr+"&custAge="+custage+"&connect="+connect+"&pwd="+pwd1+"&custNo=" +custno;
    console.log(custage);
    var url ="customer!register";
    sendRequest("post", url, date, registerResult);


}
/**
 * 查询账号是否被注册的结果
 * @param result
 */
function isExistResult(result){
    console.log(result);
    var rs = eval("(" + result + ")") ;
    if(rs == "exist")
    {
        alert("该账号已经被注册！");

        // window.location.href = "login.html?" + openid;
    }

}
/**
 * 注册账号返回结果
 * @param result
 */
function registerResult(result){
    var rs = eval("(" + result + ")") ;
    if(rs == "success")
    {
        alert("注册成功！");
        sessionStorage.setItem('custno',  document.getElementById("custno").value);
         window.location.href = "login.html";

    }

}